package net.lab1024.sa.admin.module.business.lcy.student.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.lcy.student.dao.LcyStudentDao;
import net.lab1024.sa.admin.module.business.lcy.student.domain.entity.LcyStudentEntity;
import net.lab1024.sa.admin.module.business.lcy.student.domain.form.LcyStudentAddForm;
import net.lab1024.sa.admin.module.business.lcy.student.domain.form.LcyStudentQueryForm;
import net.lab1024.sa.admin.module.business.lcy.student.domain.form.LcyStudentUpdateForm;
import net.lab1024.sa.admin.module.business.lcy.student.domain.vo.LcyStudentVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 学生基本信息 Service
 *
 * @Author yangz
 * @Date 2025-10-31 18:41:13
 * @Copyright yangz
 */

@Service
public class LcyStudentService {

    @Resource
    private LcyStudentDao lcyStudentDao;

    /**
     * 分页查询
     */
    public PageResult<LcyStudentVO> queryPage(LcyStudentQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<LcyStudentVO> list = lcyStudentDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(LcyStudentAddForm addForm) {
        LcyStudentEntity lcyStudentEntity = SmartBeanUtil.copy(addForm, LcyStudentEntity.class);
        lcyStudentDao.insert(lcyStudentEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(LcyStudentUpdateForm updateForm) {
        LcyStudentEntity lcyStudentEntity = SmartBeanUtil.copy(updateForm, LcyStudentEntity.class);
        lcyStudentDao.updateById(lcyStudentEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        lcyStudentDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long studentId) {
        if (null == studentId){
            return ResponseDTO.ok();
        }

        lcyStudentDao.updateDeleted(studentId, true);
        return ResponseDTO.ok();
    }
}
